using System;
using System.Data;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Collections.Generic;

namespace teavch.Utilities.Electrical.Design.Gui.LineDiagram
{
	public partial class Feeder : ElectricalSymbol
	{
		
		private int _feederWidth = 2;

		public Feeder()
		{
			InitializeComponent();
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Width of the Feeder" )]
		public int FeederWidth
		{
			get { return _feederWidth; }
			set
			{
				this._feederWidth = ( value % 2 ) == 0 ? value : value + 1;
				this.Refresh();
			}
		}

		protected override void OnPaint( PaintEventArgs e )
		{
			base.OnPaint( e );
			this.Paint( e );
		}
		
		protected override void OnResize( EventArgs e )
		{
			base.OnResize( e );
			this.Refresh();
		}

		private new void Paint( PaintEventArgs pea )
		{
			int _x1 = 0;
			int _y1 = 0;

			int _tx1 = 0, _ty1 = 0;
			int _tx2 = 0, _ty2 = 0;
			int _tx3 = 0, _ty3 = 0;

			_x1 = this._feederWidth;
			_y1 = 0;

			this.Width = ( this._feederWidth * 3 ) + 1;
			this.Height = this.SymbolSize;

			_tx1 = 0;
			_ty1 = ( int ) Math.Ceiling( this.SymbolSize * .9 );

			_tx2 = ( this._feederWidth * 3 );
			_ty2 = ( int ) Math.Ceiling( this.SymbolSize * .9 );

			_tx3 = ( int ) Math.Ceiling( _tx2 * .5 );
			_ty3 = this.SymbolSize;

			System.Drawing.Drawing2D.GraphicsPath _gpath = new System.Drawing.Drawing2D.GraphicsPath();

			_gpath.AddRectangle( new Rectangle( new Point( _x1, _y1 ), new Size( this._feederWidth, ( int ) ( this.SymbolSize * .95 ) ) ) );
			pea.Graphics.FillPath( this.Brush, _gpath );
			_gpath.CloseFigure();
			_gpath.AddPolygon( new Point[] { new Point( _tx1, _ty1 ), new Point( _tx2, _ty2), new Point( _tx3, _ty3 ) } );
			pea.Graphics.FillPath( this.Brush, _gpath );
			pea.Graphics.DrawPath( this.Pen, _gpath );
		}

	}
}
